
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })

import { Toast, Notify } from 'vant';
Toast.allowMultiple();
// import { ElLoading } from 'element-plus'
// 测试获取数据
const listData = [
  {access:'ADMIN,SUP_ADMIN,OP_ADMIN',permission:'edit,add,del',account:'xialuote',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/536/536.jpg',status:1,type:1,email:'sgj@1**.com',mobel:'18800008888',title:"刮痧师傅",name:"夏洛特",amount:200,address:"上海虹桥机场"},
  {access:'ADMIN,OP_ADMIN',permission:'edit',account:'aguduo',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/533/533.jpg',status:1,type:2,email:'sgj@1**.com',mobel:'135****5421',title:"野区混子",name:"阿古朵",amount:1000,address:"南山区天美大厦"},
  {access:'SUP_ADMIN',permission:'edit,add',account:'mengtian',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/527/527.jpg',status:0,type:0,email:'sgj@1**.com',mobel:'136****5421',title:"充电宝",name:"蒙恬",amount:800,address:"南山区腾讯大厦"},
  {access:'OP_ADMIN',permission:'edit,add',account:'jing',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/531/531.jpg',status:2,type:2,email:'sgj@1**.com',mobel:'137****5421',title:"野区脆皮",name:"镜",amount:300,address:"南山区比克大厦"},
  {access:'ADMIN',permission:'edit,del',account:'mengya',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/524/524.jpg',status:2,type:3,email:'sgj@1**.com',mobel:'138****5421',title:"下路塔兵",name:"蒙犽",amount:500,address:"福田区科技园"},
  {access:'ADMIN',permission:'',account:'lubandashi',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/525/525.jpg',status:2,type:1,email:'sgj@1**.com',mobel:'139****5421',title:"鲁班他爹",name:"鲁班大师",amount:100,address:"民乐万达广场"},
  {access:'ADMIN',permission:'add,del',account:'xishi',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/523/523.jpg',status:0,type:2,email:'sgj@1**.com',mobel:'157****5421',title:"可中可辅",name:"西施",amount:400,address:"龙华高铁站"},
  {access:'ADMIN',permission:'del',account:'machao',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/518/518.jpg',status:1,type:1,email:'sgj@1**.com',mobel:'150****5421',title:"针灸师傅",name:"马超",amount:900,address:"福田区世纪佳缘"},
  {access:'ADMIN',permission:'edit',account:'yao',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/522/522.jpg',status:1,type:2,email:'sgj@1**.com',mobel:'180****5421',title:"野区话痨",name:"曜",amount:1200,address:"南山区深大地铁站"},
  {access:'ADMIN',permission:'add',account:'yunzhongjun',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/506/506.jpg',status:1,type:1,email:'sgj@1**.com',mobel:'188****5421',title:"猥琐发育",name:"云中君",amount:700,address:"北京育新地铁站"},
  {access:'ADMIN',permission:'edit,del',account:'yao',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/505/505.jpg',status:2,type:1,email:'sgj@1**.com',mobel:'189****5421',title:"辅助混子",name:"瑶",amount:500,address:"成都科技高新园"},
  {access:'ADMIN',permission:'edit,add,del',account:'change',img:'https://game.gtimg.cn/images/yxzj/img201606/heroimg/515/515.jpg',status:2,type:1,email:'sgj@1**.com',mobel:'189****5421',title:"中路混子",name:"嫦娥",amount:500,address:"成都科技高新园"},
]
// 随机字符串 id
const randomId = () => {
    let s4 = function() {
        return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
    }
    return (s4() + s4() + "-" + s4() + "-4" + s4().substr(0, 3) + "-" + s4() + "-" + s4() + s4() + s4()).toUpperCase();
}

// 模拟api获取测试数据
export const testApi = function (page=1, size=10, data, total=25,showLoading=true) {
    // uni.showLoading({ title: '加载中...' })
    let loadToast;
    if(showLoading){
      NProgress.start()
      // loadToast = Toast.loading({
      //   message: '加载中',
      //   forbidClick: true,
      //   duration:0
      // });
      // loadToast = ElLoading.service({ 
      //   lock: true,
      //   fullscreen: true,
      //   text: 'Loading',
      //   spinner: 'el-icon-loading',
      //   background: 'rgba(0,0,0,.0)' 
      // })
    }
    const isnumb = typeof data !== 'object' && typeof data === 'number' && !isNaN(data)
    total = isnumb ? data : total
    const start = (page - 1) * size + 1
    const end = page * size
    const leng = end >= total ?  total : end
    return new Promise((resolve,reject)=>{
      let list = [];
      if(start<=total){
        for (let i = start; i <= leng; i++) {
            let item = Object.assign({}, listData[ Math.floor(Math.random() * 10)], data);
            item.id = randomId();
            item.key = i;
            item.time = new Date()
            list.push(item);
        }
      }
      setTimeout(() => {
        // uni.hideLoading();
        loadToast && loadToast.close()
        NProgress.done()
        let data = {
          status: 1,
          data: list,
          msg: '查询成功',
          total
        }
        resolve(data)
      }, 1000);
    })
  }
  